package com.fr.report.write.config;

import com.fr.base.ArrayUtils;
import com.fr.base.ColumnRow;
import com.fr.base.ColumnRowRelated;
import com.fr.base.XMLable;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.report.cellElement.core.CellElementAttribute;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.parameter.Parameter;
import com.fr.report.script.Calculator;

public class ColumnConfig
  implements XMLable
{
  public static final String XML_TAG = "ColumnConfig";
  private String name;
  private Object value;
  private boolean isKey;
  private boolean skipUnmodified;

  public ColumnConfig()
  {
  }

  public ColumnConfig(String paramString, Object paramObject, boolean paramBoolean1, boolean paramBoolean2)
  {
    this.name = paramString;
    this.value = paramObject;
    this.isKey = paramBoolean1;
    this.skipUnmodified = paramBoolean2;
  }

  public String getColumnName()
  {
    return this.name;
  }

  public void setColumnName(String paramString)
  {
    this.name = paramString;
  }

  public Object getColumnValue()
  {
    return this.value;
  }

  public boolean isModified(Calculator paramCalculator)
  {
    ColumnRow[] arrayOfColumnRow;
    int i;
    if (this.value instanceof ColumnRowRelated)
    {
      arrayOfColumnRow = ((ColumnRowRelated)this.value).getRelatedColumnRows();
      if (!(ArrayUtils.isEmpty(arrayOfColumnRow)))
        for (i = 0; i < arrayOfColumnRow.length; ++i)
        {
          Object localObject1 = paramCalculator.resolveCellElementAttribute(arrayOfColumnRow[i], CellElementAttribute.INSERT_NEW);
          if (localObject1 != null)
            return true;
          Object localObject2 = paramCalculator.resolveCellElementAttribute(arrayOfColumnRow[i], CellElementAttribute.ORIGINAL);
          Object localObject3 = paramCalculator.resolveVariable(arrayOfColumnRow[i]);
          if (!(ComparatorUtils.equals(localObject2, localObject3)))
            return true;
        }
    }
    return false;
  }

  public boolean isDeleted(Calculator paramCalculator)
  {
    ColumnRow[] arrayOfColumnRow;
    int i;
    if (this.value instanceof ColumnRowRelated)
    {
      arrayOfColumnRow = ((ColumnRowRelated)this.value).getRelatedColumnRows();
      if (!(ArrayUtils.isEmpty(arrayOfColumnRow)))
        for (i = 0; i < arrayOfColumnRow.length; ++i)
        {
          Object localObject = paramCalculator.resolveCellElementAttribute(arrayOfColumnRow[i], CellElementAttribute.DEL);
          if (trueOrFalse(localObject))
            return true;
        }
    }
    return false;
  }

  private boolean trueOrFalse(Object paramObject)
  {
    if ((paramObject != null) && (paramObject.getClass().isArray()))
    {
      Object[] arrayOfObject = (Object[])paramObject;
      for (int i = 0; i < arrayOfObject.length; ++i)
        if (trueOrFalse(arrayOfObject[i]))
          return true;
      return false;
    }
    return Boolean.TRUE.equals(paramObject);
  }

  public void setColumnValue(Object paramObject)
  {
    this.value = paramObject;
  }

  public boolean isKey()
  {
    return this.isKey;
  }

  public void setKey(boolean paramBoolean)
  {
    this.isKey = paramBoolean;
  }

  public boolean isSkipUnmodified()
  {
    return this.skipUnmodified;
  }

  public void setSkipUnmodified(boolean paramBoolean)
  {
    this.skipUnmodified = paramBoolean;
  }

  public String toString()
  {
    return ((this.isKey) ? "* " : "") + this.name + ":" + this.value;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    String str1 = null;
    if (paramXMLableReader.isAttr())
    {
      if ((str1 = paramXMLableReader.getAttr("name")) != null)
        this.name = str1;
      if ((str1 = paramXMLableReader.getAttr("isKey")) != null)
        this.isKey = Boolean.valueOf(str1).booleanValue();
      if ((str1 = paramXMLableReader.getAttr("skipUnmodified")) != null)
        this.skipUnmodified = Boolean.valueOf(str1).booleanValue();
    }
    if (paramXMLableReader.isChildNode())
    {
      Object localObject;
      String str2 = paramXMLableReader.getTagName();
      if ("ColumnRow".endsWith(str2))
      {
        int i = 0;
        int j = 0;
        if ((str1 = paramXMLableReader.getAttr("column")) != null)
          i = Integer.parseInt(str1);
        if ((str1 = paramXMLableReader.getAttr("row")) != null)
          j = Integer.parseInt(str1);
        localObject = ColumnRow.valueOf(i, j);
      }
      else if ("Parameter".equals(str2))
      {
        localObject = ReportXMLUtils.readParameter(paramXMLableReader);
      }
      else if (("Object".equals(str2)) || ("O".equals(str2)))
      {
        localObject = ReportXMLUtils.readObject(paramXMLableReader);
      }
      else
      {
        localObject = "";
      }
      setColumnValue(localObject);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("ColumnConfig").attr("name", this.name).attr("isKey", this.isKey).attr("skipUnmodified", this.skipUnmodified);
    if (this.value instanceof ColumnRow)
    {
      ColumnRow localColumnRow = (ColumnRow)this.value;
      BaseXMLUtils.writeColumnRow(paramXMLPrintWriter, localColumnRow);
    }
    else if (this.value instanceof Parameter)
    {
      ReportXMLUtils.writeParameter(paramXMLPrintWriter, (Parameter)this.value);
    }
    else
    {
      ReportXMLUtils.writeObject(paramXMLPrintWriter, this.value);
    }
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof ColumnConfig))
      return false;
    ColumnConfig localColumnConfig = (ColumnConfig)paramObject;
    return ((localColumnConfig.isKey == this.isKey) && (localColumnConfig.skipUnmodified == this.skipUnmodified) && (localColumnConfig.name.equals(this.name)) && (localColumnConfig.value.equals(this.value)));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    ColumnConfig localColumnConfig = (ColumnConfig)super.clone();
    return localColumnConfig;
  }
}